import os
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
import time
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By

chrome_options = Options()
chrome_options.add_argument("--headless")

mobileEmulation = {'deviceName':'Galaxy S5'}
chrome_options.add_experimental_option('mobileEmulation', mobileEmulation)

# base_url = "http://www.baidu.com/"
base_url = "https://shop36012028.m.taobao.com/?shop_id=36012028#list"
# 对应的chromedriver的放置目录
driver = webdriver.Chrome(chrome_options=chrome_options)


def productList(base_url):
    driver.get(base_url)
    # driver.set_window_size("1649", "2535")


    # 等待指定的标签
    # element = WebDriverWait(driver, 5, 0.5).until(
    #     EC.presence_of_element_located((By.ID, "loginname"))
    # )
    # element.send_keys("lixuweiok@sina.com")
    time.sleep(2)

    # js = "window.scrollTo(0,600)"
    # driver.execute_script(js)
    # time.sleep(1)

    driver.save_screenshot('screen2.png')
    # driver.find_element_by_xpath("//*[@id=\"gl-pagenav\"]/section/div/span/select")


start_time = time.time()
print('this is start_time ', start_time)
try:
    productList(base_url)

    # js = "window.scrollTo(0,450)"
    # driver.execute_script(js)
    # time.sleep(3)



except BaseException as msg:
    print(msg)
finally:
    # 关闭所有的window
    driver.quit()

end_time = time.time()
print('this is end_time ', end_time)
